{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import sys\n",
    "import os\n",
    "sys.path.append(os.path.abspath(r\"E:\\Project\\abnormal-sound-detection\"))\n",
    "\n",
    "from utils import *\n",
    "import torch \n",
    "from torch import nn \n",
    "from torch import optim\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt \n",
    "import matplotlib\n",
    "from seaborn import heatmap\n",
    "from sklearn.metrics import *\n",
    "from collections import Counter\n",
    "from tqdm import tqdm\n",
    "\n",
    "matplotlib.rcParams[\"font.family\"] = \"Times New Roman\"\n",
    "matplotlib.rcParams[\"legend.fontsize\"] = 16\n",
    "matplotlib.rcParams[\"xtick.major.size\"] = 12\n",
    "matplotlib.rcParams[\"ytick.major.size\"] = 12"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "((1133, 12800), (285, 12800), (1133,), (285,))"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train_x, train_y = load_abnormal(\n",
    "    meta_path=\"../data/meta_0db_id_00.json\",\n",
    "    return_numpy=True,\n",
    "    train=True,\n",
    "    X_type=\"logmel\",\n",
    "    p_flag=\"normal\", n_flag=\"abnormal\"\n",
    ")\n",
    "\n",
    "test_x, test_y = load_abnormal(\n",
    "    meta_path=\"../data/meta_0db_id_00.json\",\n",
    "    return_numpy=True,\n",
    "    train=False,\n",
    "    X_type=\"logmel\",\n",
    "    p_flag=\"normal\", n_flag=\"abnormal\"\n",
    ")\n",
    "\n",
    "train_x = train_x.reshape(train_x.shape[0], -1)\n",
    "test_x = test_x.reshape(test_x.shape[0], -1)\n",
    "\n",
    "train_x.shape, test_x.shape, train_y.shape, test_y.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "model = ASSVM(C=100)\n",
    "model.fit(train_x, train_y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "model.score(test_x, test_y)"
   ]
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "4ce0e62306dd6a5716965d4519ada776f947e6dfc145b604b11307c10277ef29"
  },
  "kernelspec": {
   "display_name": "Python 3.7.6 64-bit",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
